<?php
/**
 * Object Relational Persistence Mapping Class for table: odonto_stomatology_encounter
 *
 * @package	com.athena
 * @author	LHV
 */
class EmrGeneralExamination extends ORDataObject {

	/**#@+
	 * Fields of table: emr_odonto_stomatology mapped to class members
	 */
	var $emr_general_examination_id	= '';
	var $medical_record_id		= '';	
	var $symptom		= '';
	var $diagnosis		= '';
	var $primary_icd10		= '';
	var $secondary_icd10_1		= '';
	var $secondary_icd10_2		= '';
	var $treatment		= '';
	var $note		= '';
	var $doctor_id		= '';
	var $doctor_updated_id		= '';
	var $encounter_date		= '';
	var $last_updated		= '';
	var $medical_history  = '';
	var $allergy  = '';
	/**#@-*/

	
	const ENC_TREA_SURGERY			=	'surgery';
	const ENC_TREA_MOVE				=	'move_to_other_hospital';
	const ENC_TREA_PRESCRIPTION		=	'prescription';

	/**
	 * DB Table
	 */
	var $_table = 'emr_general_examination';

	/**
	 * Primary Key
	 */
	var $_key = 'emr_general_examination_id';
	
	/**
	 * Internal Name
	 */
	var $_internalName = 'EmrGeneralExamination';

	/**
	 * Handle instantiation
	 */
	function OdontoStomatologyEncounter() {
		parent::ORDataObject();
	}
		
	public function persist() {
		$firstTime = (((int)$this->get_id()) > 0) ? false : true;
		
		parent::persist();						
		
		$sql = "UPDATE $this->_table SET last_updated = NOW() WHERE $this->_key = " . $this->get_id();		
		$this->_execute($sql);
		if ($firstTime) {
			$sql = "UPDATE $this->_table SET encounter_date = NOW() WHERE $this->_key = " . $this->get_id();
			$this->_execute($sql);
		}
		
		return true;
	}
	
	public function getObjectFromRecordId($recordId) {		
		$sql = "SELECT $this->_key FROM $this->_table WHERE medical_record_id = $recordId";
		$res = $this->_execute($sql);
		
		$id = (!$res->EOF) ? $res->fields[$this->_key] : '';		
		return Celini::newORDO($this->_internalName, $id);
	}

	
	public function getEncounterTreatmentList(){
		$list	=	array(
			self::ENC_TREA_PRESCRIPTION	=>	L10nHelper::_(self::ENC_TREA_PRESCRIPTION),
			self::ENC_TREA_SURGERY		=>	L10nHelper::_(self::ENC_TREA_SURGERY),
			self::ENC_TREA_MOVE			=>	L10nHelper::_(self::ENC_TREA_MOVE)
		);
		return $list;
	}
	
	
	public function getDoctorId(){
		return $this->doctor_id;
	}
	
	public function getDoctorName(){
		$person	=	Celini::newORDO('Employee', $this->doctor_id);		
		return $person->getName();
	}
	
	public function getUpdatedDoctorName(){
		$person	=	Celini::newORDO('Person', $this->doctor_updated_id);		
		return $person->getName();
	}
	
	public function getDiagnosis() {
		return $this->diagnosis;
	}
	
	public function getSymptom(){
		return $this->symptom;
	}

	public function getPrimaryIcd10(){
		return $this->primary_icd10;
	}
	
	public function getSecondaryIcd10_1(){
		return $this->secondary_icd10_1;
	}
	
	public function getSecondaryIcd10_2(){
		return $this->secondary_icd10_2;
	}
	
	public function getNote(){
		return $this->note;
	}
	
	public function getTreatment(){
		return $this->treatment;
	}
	
}
?>
